/* ************************************************************************

   Copyright: openWorks

   License: GPL v3

   Authors: Paz Alejandro Martin, Granda Juan Matias

************************************************************************ */

/* ************************************************************************

#asset(caraffa/*)
#asset(membrete.png)

************************************************************************ */
//FIXME *** TIPOS: ASIGNADO, PENSAR, PREGUNTAR, Z FUTURO, Z RELEASE, OW ****
//FIXME ASIGNADO ALE: en completar datos turnos sigue trayendo los de las planillas cerradas? 
//FIXME ASIGNADO ALE PEDIDO REITERADO X ROMINA: Cuando bloqueo un turno en ABMTurno, me bloquea toda la hora y no por MINUTOS.
//TODO ASIGNADO ALE: REPLANTEAR TODO MUY VIEJO habilitar pagares para todas las obras sociales
//TODO agregar en "forma de pago" en el label "Importe:" que diga "importe (30):" donde 30 es el precio actual de la prestacion en el nomenclador
//TODO ver como mostrar un listado de lo que se va a cobrar chequeando si cambió el importe en el nomenclador
//TODO Z FUTURO: en errores del JSON agregar uno que no agregue nada al alert
//TODO Z FUTURO: Agregar todo lo que se pueda a "Para Hoy"
//TODO Z FUTURO: habilitar proveedores y usuarios a todos pero sin modificacion
//TODO Z FUTURO: ver de que si no esta el paciente y se loo tiene que agregar, que lleve al formu de alta y con el DNI precargado. Esto implica modificacion de owABMClass :D
//TODO Z FUTURO: avisar cuando llegue un msg
//TODO al cerrar facturacion agregar a diario el importe en pesos i los cheques en cheques
//TODO RETORNO PLANILLA mostrar los retornados los detalles
//
//if (mysql_error()) { $error->SetError(JsonRpcError_Unknown, (__FILE__ . " - " . (__LINE__ - 2) . ": " . mysql_error())); mysql_query("ROLLBACK"); return $error; }
qx.Class.define("caraffa.Application",
{
	extend : qx.application.Standalone,
	members :
	{
		main : function()
		{
			this.base(arguments);
			caraffa.Funciones.rpcChanger();
			
			this.getRoot().set({
				blockerColor: '#bfbfbf',
				blockerOpacity: 0.6
			});

			if (qx.core.Environment.get("qx.debug")) {
				qx.log.appender.Native;
				qx.log.appender.Console;
			}

			this._version = "4.2.534";
			
			var rpc = new qx.io.remote.Rpc();
			rpc.setTimeout(10000);
			rpc.setUrl("services/");
			rpc.setServiceName("login");
			try
			{
				var params = new Object();
				params.version = this._version;
				var result = rpc.callSync("Logueado", params);
				if (!result)
				{
					caraffa.Funciones.Login("Identificacion de Usuario", "", this._InitAPP, this);
				}
				else
				{
					this._perfilUsuario = result;
					this._InitAPP();
				}
			}
			catch (ex)
			{
				alert(ex);
			}
		},
		_InitAPP : function ()
		{
			var layer = new qx.ui.container.Composite(new qx.ui.layout.Grow());
			var scroll = new qx.ui.container.Scroll();
			layer.add(scroll);
			var con = new qx.ui.container.Composite(new qx.ui.layout.VBox(2));
			con.setAllowShrinkY(false);
			
			scroll.add(con);
			scroll.setScrollbarY("auto");
			
			
			this._perfilUsuario = caraffa.Funciones.getPerfilUsuario();
			var doc = this.getRoot();
			var app = this._appFireTab = new qx.ui.form.ow.Firetab(1024, 700);
			var menu = this._getMenu();
			
			app.setMenu(menu);
			con.add(app);
			
			doc.add(layer, {edge:0});
			
			var form = new caraffa.forms.Desktop("caraffa/16/casa.png");

			app.openForm(form);
			
			

			/*
			 **** TIMER PARA MANTER ACTIVA LA SESSION ****
			 **** EN CASO DE CERRARSE, ACTIVA BLOQUEO ****
			 */
			this._tmrCheck = new qx.event.Timer(60000);
			this._tmrCheck.addListener('interval', function() {
				var rpc = new qx.io.remote.Rpc().set({timeout:10000, url:"services/", serviceName:"login"});
				try	{
					var p = new Object();
					p.version = this._version;
					var result = rpc.callSync("Logueado", p);
					if (!result) {
						this._Bloquear();
					}
				} catch (ex) {
					alert(ex);
				}
			}, this);
			this._onTimer();
			//********************************************
		},
		_onTimer : function () {
			this._tmrCheck.start();
		},
		_offTimer : function () {
			this._tmrCheck.stop();
		},
		_getMenu : function ()
		{
			var dni_usuario = this._perfilUsuario.dni_usuario;
			switch (this._perfilUsuario.cod_tipo_usuario)
			{
				// ************************
				// ** MENU SYS Admin     **
				// ************************
				case '1': 
				{
					var menu = 
					{
						"sections":
						[
							{
								"value" : "id_secretaria",
								"label" : "Secretaria",
								"icon" : "caraffa/22/personaBlanca.png",
								"items" : // siempre tiene mas peso esta opcion
								[
									{ "value" : "1", "label" : "Turnos Zipoli", "icon" : "caraffa/22/calendario.png", "action" : this.Turnos, "context": this },
									{ "value" : "2", "label" : "Turnos Avellaneda", "icon" : "caraffa/22/calendario.png", "action" : this.TurnosAvellaneda, "context": this },
									{ "value" : "id_item2", "label" : "Buscar Turnos", "icon" : "caraffa/22/largavista.png", "action" : this.BuscarTurnoPaciente, "context": this },
									{ "value" : "id_item3", "label" : "Completar datos del Turno", "icon" : "caraffa/22/anotadorVisto.png", "action" : this.CompletarTurnos, "context": this },
									{ "separator": true},
									{ "value" : "id_item4", "label" : "ABM Pacientes", "icon" : "caraffa/22/personas.png", "action" : this.ABMPacientes, "context": this },
									{ "separator": true},
									{ "value" : "id_item5", "label" : "Anotador", "icon" : "caraffa/22/anotador.png", "action" : this.Anotador, "context": this }
								]
							},
							{
								"value" : "id_medico",
								"label" : "Medico",
								"icon" : "caraffa/22/trajes.png",
								"items" : // siempre tiene mas peso esta opcion
								[
									{ "value" : "id_item0", "label" : "Agenda", "icon" : "caraffa/22/agenda.png", "action" : this.ABMAgenda, "context": this },
									{ "value" : "id_item1", "label" : "Turnos de la semana", "icon" : "caraffa/22/calendario.png", "action" : this.AgendaMedico, "context": this },
									{ "value" : "id_item2", "label" : "Duración del Turno", "icon" : "caraffa/22/reloj2.png", "action" : this.DuracionTurno, "context": this },
									{ "value" : "id_item3", "label" : "Historias Clínicas", "icon" : "caraffa/22/anotador.png", "action" : this.HistoriasClinicas, "context": this },
									{ "value" : "id_item4", "label" : "Cirugias", "icon" : "caraffa/22/visturi.png", "action" : this.Cirugias, "context": this }
								]
							},					
							{
								"value" : "id_Caja",
								"label" : "Cajas",
								"icon" : "caraffa/22/caja.png",
								"items" : // siempre tiene mas peso esta opcion
								[
									
									{ "value" : "id_item1", "label" : "Caja - Ingresos Zipoli", "icon" : "caraffa/22/caja.png", "action" : this.CajaIngresoCustomZipoli, "context": this },
									{ "value" : "id_item1", "label" : "Caja - Ingresos Avellaneda", "icon" : "caraffa/22/caja.png", "action" : this.CajaIngresoCustomAvellaneda, "context": this },
									{ "separator": true},
									
									{ "value" : "id_item1", "label" : "Caja Mensual: Zipoli", "icon" : "caraffa/22/caja.png", "action" : this.CajaActualCaraffa, "context": this },
									{ "value" : "id_item1", "label" : "Caja Mensual: Avellaneda", "icon" : "caraffa/22/caja.png", "action" : this.CajaActualAvellaneda, "context": this },
									{ "separator": true},
									{ "value" : "id_item2", "label" : "Caja Mensuales Control", "icon" : "caraffa/22/caja.png", "action" : this.CajaControl, "context": this },
									{ "value" : "id_item3", "label" : "ABM Rubros Caja", "icon" : "caraffa/22/caja.png", "action" : this.ABMCajaRubros, "context": this },
									{ "separator": true},									
									{ "value" : "id_item4", "label" : "Pagares", "icon" : "caraffa/22/caja.png", "action" : this.Pagares, "context": this}
								]
							},					
							{
								"value" : "id_inventario",
								"label" : "Inventario",
								"icon" : "caraffa/22/anotador.png",
								"items" : // siempre tiene mas peso esta opcion
								[
									{ "value" : "id_item0", "label" : "Manejo de Stock", "icon" : "caraffa/22/base.png", "action" : this.StockManejo, "context": this },
									{ "value" : "id_item1", "label" : "Movimientos Mensuales", "icon" : "caraffa/22/actualizar2.png", "action" : this.StockMensual, "context": this },
									{ "separator": true},
									{ "value" : "id_item2", "label" : "ABM Articulos", "icon" : "caraffa/22/caja2.png", "action" : this.ABMArticulos, "context": this },
									{ "value" : "id_item4", "label" : "ABM Partidas", "icon" : "caraffa/22/flecha2Derecha.png", "action" : this.ABMPartidas, "context": this },
									{ "separator": true},
									{ "value" : "id_item3", "label" : "ABM Marcas", "icon" : "caraffa/22/etiqueta.png", "action" : this.ABMMarcas, "context": this },
									{ "value" : "id_item5", "label" : "ABM Proveedores", "icon" : "caraffa/22/telefono.png", "action" : this.ABMProveedores, "context": this },
									{ "value" : "id_item6", "label" : "ABM Rubros", "icon" : "caraffa/22/archivos.png", "action" : this.ABMRubros, "context": this }
									
									
								]
							},
							{
								"value" : "id_obrasSociales",
								"label" : "Obras Sociales",
								"icon" : "caraffa/22/tarjeta.png",
								"items" : // siempre tiene mas peso esta opcion
								[
									{ "value" : "id_item1", "label" : "Generación de Planillas", "icon" : "caraffa/22/libroCerrado.png", "action" : this.GeneraPlanillas, "context": this },
									{ "value" : "id_item2", "label" : "Lista de Planillas", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ListaPlanillasOS, "context": this },
									{ "value" : "id_item3", "label" : "Retorno de Planilla", "icon" : "caraffa/22/libroCerrado.png", "action" : this.CheckPlanilla, "context": this },
									{separator: true},
									{ "value" : "id_item3", "label" : "Carga de Balances", "icon" : "caraffa/22/libroCerrado.png", "action" : this.BalancesCarga, "context": this },
									{ "value" : "id_item3", "label" : "Listar Balances", "icon" : "caraffa/22/libroCerrado.png", "action" : this.BalancesListar, "context": this },
									{ "value" : "id_item3", "label" : "Listar Derivaciones", "icon" : "caraffa/22/libroCerrado.png", "action" : this.Derivaciones, "context": this },
									{separator: true},
									{ "value" : "id_item4", "label" : "3 ABM Nomenclador", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ABMNomenclador, "context": this },
									{ "value" : "id_item5", "label" : "2 ABM Prestaciones", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ABMPrestaciones, "context": this },
									{ "value" : "id_item6", "label" : "1 ABM Prestaciones Rubros", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ABMPrestacionesRubros, "context": this },
									{ "value" : "id_item7", "label" : "1 ABM Planes", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ABMPlanes, "context": this },
									{separator: true},
									{ "value" : "id_item8", "label" : "Carga/Cierre de Turnos", "icon" : "caraffa/22/calendario.png", "action" : this.CargaTurnos, "context": this }
								]
							},					
							{
								"value" : "id_estadisticas",
								"label" : "Estadísticas",
								"icon" : "caraffa/22/archivoEstadistica.png",
								"items" : // siempre tiene mas peso esta opcion
								[
									{ "value" : "id_item0", "label" : "Pacientes Atendidos/Médicos", "icon" : "caraffa/22/archivoBase.png", "action" : this.ChartPacientesMedicoMes, "context": this },
									{ "value" : "id_item2", "label" : "Pacientes Atendidos/OSocial", "icon" : "caraffa/22/archivoBase.png", "action" : this.ChartPacientesOSAnio, "context": this },
									{ "separator" : true},
									{ "value" : "id_item0", "label" : "Numeros Generales", "icon" : "caraffa/22/archivoBase.png", "action" : this.ChartNumerosGrales, "context": this },
									{ "value" : "id_item0", "label" : "Consultas, Practicas y Cirugias", "icon" : "caraffa/22/archivoBase.png", "action" : this.ChartCPC, "context": this }
									//{ "value" : "id_item1", "label" : "O. Social Diferencia Cobro", "icon" : "caraffa/22/archivoBase.png", "action" : this.ChartOSCobradoPagado, "context": this },
									
		
								]
							},
							{
								"value" : "id_usuarios",
								"label" : "Usuarios",
								"icon" : "caraffa/22/personas.png",
								"items" : // siempre tiene mas peso esta opcion
								[
									{ "value" : "id_item1", "label" : "ABM Usuarios", "icon" : "caraffa/22/persona.png", "action" : this.ABMUsuarios, "context": this },
									{ "value" : "id_item2", "label" : "ABM Grupos", "icon" : "caraffa/22/personas2.png", "action" : this.ABMGrupos, "context": this }
								]
							},
							
							{
								"op_menu" : "spacer"
							},
							{
								"value" : "id_password",
								"label" : "Cambiar Password",
								"icon" : "caraffa/16/llaves.png",
								"action" : this._CambiarPassword,
								"context" : this
							},
							{
								"value" : "id_bloquear",
								"label" : "Bloquear",
								"icon" : "caraffa/16/candadoCerrado.png",
								"action" : this._Bloquear,
								"context" : this
							},
							{
								"value" : "id_salir",
								"label" : "Salir",
								"icon" : "caraffa/22/salir.png",
								"action" : this.Logout // esta opcion es en caso de que no querramos que se forme un submenu, sino un simple boton.
							}
						]
					};
					break;
				}
				// *********************
				// ** MENU Secretaria **
				// *********************
				case '2':
				{
					var menu = 
					{
						"sections":
						[
							{
								"value" : "id_secretaria",
								"label" : "Secretaria",
								"icon" : "caraffa/22/personaBlanca.png",
								"items" :
								[
									{ "value" : "1", "label" : "Turnos Zipoli", "icon" : "caraffa/22/calendario.png", "action" : this.Turnos, "context": this },
									{ "value" : "2", "label" : "Turnos Avellaneda", "icon" : "caraffa/22/calendario.png", "action" : this.TurnosAvellaneda, "context": this },
									{ "value" : "id_item2", "label" : "Buscar Turnos", "icon" : "caraffa/22/largavista.png", "action" : this.BuscarTurnoPaciente, "context": this },
									{ "value" : "id_item3", "label" : "Completar datos del Turno", "icon" : "caraffa/22/anotadorVisto.png", "action" : this.CompletarTurnos, "context": this },
									{ "separator": true},
									{ "value" : "id_item4", "label" : "Anotador", "icon" : "caraffa/22/anotador.png", "action" : this.Anotador, "context": this }									
								]
							},
							{
								"value" : "id_paciente",
								"label" : "Pacientes",
								"icon" : "caraffa/22/personas2.png",
								"items" :								
								[
									{ "value" : "id_item0", "label" : "ABM Pacientes", "icon" : "caraffa/22/personas.png", "action" : this.ABMPacientes, "context": this },								
									{ "value" : "id_item1", "label" : "Cirugias", "icon" : "caraffa/22/visturi.png", "action" : this.Cirugias, "context": this },
									{ "value" : "id_item2", "label" : "Historias Clínicas", "icon" : "caraffa/22/anotador.png", "action" : this.HistoriasClinicas, "context": this }
								]
							},
							{
								"value" : "id_medico",
								"label" : "Medico",
								"icon" : "caraffa/22/trajes.png",
								"items" : // siempre tiene mas peso esta opcion
								[
									{ "value" : "id_item0", "label" : "Agenda", "icon" : "caraffa/22/agenda.png", "action" : this.ABMAgenda, "context": this },
									{ "value" : "id_item2", "label" : "Duración del Turno", "icon" : "caraffa/22/reloj2.png", "action" : this.DuracionTurno, "context": this }
								]
							},												
							{
								"value" : "id_Caja",
								"label" : "Cajas",
								"icon" : "caraffa/22/caja.png",
								"items" :								
								[
									{ "value" : "id_item1", "label" : "Caja - Ingresos Zipoli", "icon" : "caraffa/22/caja.png", "action" : this.CajaIngresoCustomZipoli, "context": this },
									{ "value" : "id_item1", "label" : "Caja - Ingresos Avellaneda", "icon" : "caraffa/22/caja.png", "action" : this.CajaIngresoCustomAvellaneda, "context": this }
								]
							},					
							{
								"value" : "id_obrasSociales",
								"label" : "Obras Sociales",
								"icon" : "caraffa/22/tarjeta.png",
								"items" :								
								[
									{ "value" : "id_item1", "label" : "Generación de Planillas", "icon" : "caraffa/22/libroCerrado.png", "action" : this.GeneraPlanillas, "context": this },
									{ "value" : "id_item2", "label" : "Lista de Planillas", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ListaPlanillasOS, "context": this },
									{ "value" : "id_item3", "label" : "Retorno de Planilla", "icon" : "caraffa/22/libroCerrado.png", "action" : this.CheckPlanilla, "context": this },
									{separator: true},
									{ "value" : "id_item4", "label" : "3 ABM Nomenclador", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ABMNomenclador, "context": this },
									{ "value" : "id_item5", "label" : "2 ABM Prestaciones", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ABMPrestaciones, "context": this },
									{ "value" : "id_item6", "label" : "1 ABM Prestaciones Rubros", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ABMPrestacionesRubros, "context": this },
									{ "value" : "id_item7", "label" : "1 ABM Planes", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ABMPlanes, "context": this }
								]
							},					
							{
								"op_menu" : "spacer"
							},
							{
								"value" : "id_password",
								"label" : "Cambiar Password",
								"icon" : "caraffa/16/llaves.png",
								"action" : this._CambiarPassword,
								"context" : this
							},
							{
								"value" : "id_bloquear",
								"label" : "Bloquear",
								"icon" : "caraffa/16/candadoCerrado.png",
								"action" : this._Bloquear,
								"context" : this
							},
							{
								"value" : "id_salir",
								"label" : "Salir",
								"icon" : "caraffa/22/salir.png",
								"action" : this.Logout // esta opcion es en caso de que no querramos que se forme un submenu, sino un simple boton.
							}
						]
					};
					break;
				}
				// ************************
				// ** MENU Administrador **
				// ************************
				case '5':
				{
					var menu = 
					{
						"sections":
						[
							{
								"value" : "id_secretaria",
								"label" : "Secretaria",
								"icon" : "caraffa/22/personaBlanca.png",
								"items" :
								[
									{ "value" : "1", "label" : "Turnos Zipoli", "icon" : "caraffa/22/calendario.png", "action" : this.Turnos, "context": this },
									{ "value" : "2", "label" : "Turnos Avellaneda", "icon" : "caraffa/22/calendario.png", "action" : this.TurnosAvellaneda, "context": this },
									{ "value" : "id_item2", "label" : "Buscar Turnos", "icon" : "caraffa/22/largavista.png", "action" : this.BuscarTurnoPaciente, "context": this },
									{ "value" : "id_item3", "label" : "Completar datos del Turno", "icon" : "caraffa/22/anotadorVisto.png", "action" : this.CompletarTurnos, "context": this },
									{ "separator": true},
									{ "value" : "id_item4", "label" : "Anotador", "icon" : "caraffa/22/anotador.png", "action" : this.Anotador, "context": this }									
								]
							},
							{
								"value" : "id_paciente",
								"label" : "Pacientes",
								"icon" : "caraffa/22/personas2.png",
								"items" :								
								[
									{ "value" : "id_item0", "label" : "ABM Pacientes", "icon" : "caraffa/22/personas.png", "action" : this.ABMPacientes, "context": this },								
									{ "value" : "id_item1", "label" : "Cirugias", "icon" : "caraffa/22/visturi.png", "action" : this.Cirugias, "context": this },
									{ "value" : "id_item2", "label" : "Historias Clínicas", "icon" : "caraffa/22/anotador.png", "action" : this.HistoriasClinicas, "context": this }
								]
							},
							{
								"value" : "id_medico",
								"label" : "Medico",
								"icon" : "caraffa/22/trajes.png",
								"items" : // siempre tiene mas peso esta opcion
								[
									{ "value" : "id_item0", "label" : "Agenda", "icon" : "caraffa/22/agenda.png", "action" : this.ABMAgenda, "context": this },
									{ "value" : "id_item2", "label" : "Duración del Turno", "icon" : "caraffa/22/reloj2.png", "action" : this.DuracionTurno, "context": this }
								]
							},												
							{
								"value" : "id_Caja",
								"label" : "Cajas",
								"icon" : "caraffa/22/caja.png",
								"items" :								
								[
									
									{ "value" : "id_item1", "label" : "Caja - Ingresos Zipoli", "icon" : "caraffa/22/caja.png", "action" : this.CajaIngresoCustomZipoli, "context": this },
									{ "value" : "id_item1", "label" : "Caja - Ingresos Avellaneda", "icon" : "caraffa/22/caja.png", "action" : this.CajaIngresoCustomAvellaneda, "context": this },
									{ "separator": true},
									{ "value" : "id_item1", "label" : "Caja Mensual Caraffa", "icon" : "caraffa/22/caja.png", "action" : this.CajaActualCaraffa, "context": this },
									{ "value" : "id_item1", "label" : "Caja Mensual Avellaneda", "icon" : "caraffa/22/caja.png", "action" : this.CajaActualAvellaneda, "context": this },									
									{ "value" : "id_item2", "label" : "Caja Mensuales Control", "icon" : "caraffa/22/caja.png", "action" : this.CajaControl, "context": this },
									{ "value" : "id_item3", "label" : "ABM Rubros Caja", "icon" : "caraffa/22/caja.png", "action" : this.ABMCajaRubros, "context": this },
									
									{ "separator": true},									
									{ "value" : "id_item4", "label" : "Pagares", "icon" : "caraffa/22/caja.png", "action" : this.Pagares, "context": this}
								]
							},					
							{
								"value" : "id_obrasSociales",
								"label" : "Obras Sociales",
								"icon" : "caraffa/22/tarjeta.png",
								"items" :								
								[
									{ "value" : "id_item1", "label" : "Generación de Planillas", "icon" : "caraffa/22/libroCerrado.png", "action" : this.GeneraPlanillas, "context": this },
									{ "value" : "id_item2", "label" : "Lista de Planillas", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ListaPlanillasOS, "context": this },
									{ "value" : "id_item3", "label" : "Retorno de Planilla", "icon" : "caraffa/22/libroCerrado.png", "action" : this.CheckPlanilla, "context": this },
									{separator: true},
									{ "value" : "id_item3", "label" : "Carga de Balances", "icon" : "caraffa/22/libroCerrado.png", "action" : this.BalancesCarga, "context": this },
									{ "value" : "id_item3", "label" : "Listar Balances", "icon" : "caraffa/22/libroCerrado.png", "action" : this.BalancesListar, "context": this },
									{ "value" : "id_item3", "label" : "Listar Derivaciones", "icon" : "caraffa/22/libroCerrado.png", "action" : this.Derivaciones, "context": this },
									{separator: true},
									{ "value" : "id_item4", "label" : "3 ABM Nomenclador", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ABMNomenclador, "context": this },
									{ "value" : "id_item5", "label" : "2 ABM Prestaciones", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ABMPrestaciones, "context": this },
									{ "value" : "id_item6", "label" : "1 ABM Prestaciones Rubros", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ABMPrestacionesRubros, "context": this },
									{ "value" : "id_item7", "label" : "1 ABM Planes", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ABMPlanes, "context": this },
									{separator: true},
									{ "value" : "id_item8", "label" : "Carga/Cierre de Turnos", "icon" : "caraffa/22/calendario.png", "action" : this.CargaTurnos, "context": this }
								]
							},					
							{
								"op_menu" : "spacer"
							},
							{
								"value" : "id_password",
								"label" : "Cambiar Password",
								"icon" : "caraffa/16/llaves.png",
								"action" : this._CambiarPassword,
								"context" : this
							},
							{
								"value" : "id_bloquear",
								"label" : "Bloquear",
								"icon" : "caraffa/16/candadoCerrado.png",
								"action" : this._Bloquear,
								"context" : this
							},
							{
								"value" : "id_salir",
								"label" : "Salir",
								"icon" : "caraffa/22/salir.png",
								"action" : this.Logout // esta opcion es en caso de que no querramos que se forme un submenu, sino un simple boton.
							}
						]
					};
					break;
				}				
				case '3':
				{
					//cugno=11190961; vargas=11240054; martinez=12744863
					if(dni_usuario == 11190961 || dni_usuario == 11240054 || dni_usuario == 12744863 ){
					// ***********************
					// ** MENU Medico/ADMIN **
					// ***********************
						var menu = 
						{
							"sections":
							[
								{ "value" : "id_item0", "label" : "Agenda", "icon" : "caraffa/22/agenda.png", "action" : this.ABMAgenda, "context": this },
								{ "value" : "id_item1", "label" : "Turnos de la semana", "icon" : "caraffa/22/calendario.png", "action" : this.AgendaMedico, "context": this },
								{ "value" : "id_item2", "label" : "Duración del Turno", "icon" : "caraffa/22/reloj2.png", "action" : this.DuracionTurno, "context": this },
								{ "value" : "id_item3", "label" : "Historias Clínicas", "icon" : "caraffa/22/anotador.png", "action" : this.HistoriasClinicas, "context": this },
								{ "value" : "id_item4", "label" : "Cirugias", "icon" : "caraffa/22/visturi.png", "action" : this.Cirugias, "context": this },
								{
									"value" : "id_medicoAdmin",
									"label" : "Administración",
									"icon" : "caraffa/22/tarjeta.png",
									"items" :								
									[
										{ "value" : "id_item2", "label" : "Control Cajas", "icon" : "caraffa/22/caja.png", "action" : this.CajaControl, "context": this },								
										{separator: true},
										{ "value" : "id_item4", "label" : "Nomenclador", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ABMNomenclador, "context": this },									
										{ "value" : "id_item2", "label" : "Lista de Planillas", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ListaPlanillasOS, "context": this },
										{separator: true},
										{ "value" : "id_item1", "label" : "Stock Movimientos", "icon" : "caraffa/22/actualizar2.png", "action" : this.StockMensual, "context": this }									
									]
								},												
								{
									"op_menu" : "spacer"
								},
								{
									"value" : "id_password",
									"label" : "Cambiar Password",
									"icon" : "caraffa/16/llaves.png",
									"action" : this._CambiarPassword,
									"context" : this
								},
								{
									"value" : "id_bloquear",
									"label" : "Bloquear",
									"icon" : "caraffa/16/candadoCerrado.png",
									"action" : this._Bloquear,
									"context" : this
								},
								{
									"value" : "id_salir",
									"label" : "Salir",
									"icon" : "caraffa/22/salir.png",
									"action" : this.Logout // esta opcion es en caso de que no querramos que se forme un submenu, sino un simple boton.
								}
							]
						};		
					}
					else{
						// *****************
						// ** MENU Medico **
						// *****************
						var menu = 
						{						
							"sections":
							[
								{ "value" : "id_item0", "label" : "Agenda", "icon" : "caraffa/22/agenda.png", "action" : this.ABMAgenda, "context": this },
								{ "value" : "id_item1", "label" : "Turnos de la semana", "icon" : "caraffa/22/calendario.png", "action" : this.AgendaMedico, "context": this },
								{ "value" : "id_item2", "label" : "Duración del Turno", "icon" : "caraffa/22/reloj2.png", "action" : this.DuracionTurno, "context": this },
								{ "value" : "id_item3", "label" : "Historias Clínicas", "icon" : "caraffa/22/anotador.png", "action" : this.HistoriasClinicas, "context": this },
								{ "value" : "id_item4", "label" : "Cirugias", "icon" : "caraffa/22/visturi.png", "action" : this.Cirugias, "context": this },
								{ "value" : "id_item4", "label" : "Nomenclador", "icon" : "caraffa/22/libroCerrado.png", "action" : this.ABMNomenclador, "context": this },
								{
									"op_menu" : "spacer"
								},
								{
									"value" : "id_password",
									"label" : "Cambiar Password",
									"icon" : "caraffa/16/llaves.png",
									"action" : this._CambiarPassword,
									"context" : this
								},
								{
									"value" : "id_bloquear",
									"label" : "Bloquear",
									"icon" : "caraffa/16/candadoCerrado.png",
									"action" : this._Bloquear,
									"context" : this
								},
								{
									"value" : "id_salir",
									"label" : "Salir",
									"icon" : "caraffa/22/salir.png",
									"action" : this.Logout // esta opcion es en caso de que no querramos que se forme un submenu, sino un simple boton.
								}
							]
						};
					}
					break;
				}
				// ************************
				// ** MENU Inventario **
				// ************************
				case '4': 
				{
					var menu = 
					{
						"sections":
						[
							{
								"value" : "id_inventario",
								"label" : "Inventario",
								"icon" : "caraffa/22/anotador.png",
								"items" : // siempre tiene mas peso esta opcion
								[
									{ "value" : "id_item0", "label" : "Manejo de Stock", "icon" : "caraffa/22/base.png", "action" : this.StockManejo, "context": this },
									{ "value" : "id_item1", "label" : "Movimientos Mensuales", "icon" : "caraffa/22/actualizar2.png", "action" : this.StockMensual, "context": this },
									{ "separator": true},
									{ "value" : "id_item2", "label" : "ABM Articulos", "icon" : "caraffa/22/caja2.png", "action" : this.ABMArticulos, "context": this },
									{ "value" : "id_item4", "label" : "ABM Partidas", "icon" : "caraffa/22/flecha2Derecha.png", "action" : this.ABMPartidas, "context": this },
									{ "separator": true},
									{ "value" : "id_item3", "label" : "ABM Marcas", "icon" : "caraffa/22/etiqueta.png", "action" : this.ABMMarcas, "context": this },
									{ "value" : "id_item5", "label" : "ABM Proveedores", "icon" : "caraffa/22/telefono.png", "action" : this.ABMProveedores, "context": this },
									{ "value" : "id_item6", "label" : "ABM Rubros", "icon" : "caraffa/22/archivos.png", "action" : this.ABMRubros, "context": this }
									
									
								]
							},
							{
								"op_menu" : "spacer"
							},
							{
								"value" : "id_password",
								"label" : "Cambiar Password",
								"icon" : "caraffa/16/llaves.png",
								"action" : this._CambiarPassword,
								"context" : this
							},
							{
								"value" : "id_bloquear",
								"label" : "Bloquear",
								"icon" : "caraffa/16/candadoCerrado.png",
								"action" : this._Bloquear,
								"context" : this
							},
							{
								"value" : "id_salir",
								"label" : "Salir",
								"icon" : "caraffa/22/salir.png",
								"action" : this.Logout // esta opcion es en caso de que no querramos que se forme un submenu, sino un simple boton.
							}
						]
					};
					break;
				}				
			}
			return menu;
		},
// Secretaria
		Turnos : function ()
		{
			if (this._appFireTab.isOpen("TurnosZipoli"))
			{
				this._appFireTab.setFocusForm("TurnosZipoli");
			}
			else
			{
//				var form = new qx.ui.form.ow.FormTab("Turnos", "Turnos");
//				form.add(new caraffa.widgets.Turnos());
				var form = new caraffa.widgets.Turnos(null, null, 1);
				this._appFireTab.openForm(form);
			}
			
		},
		TurnosAvellaneda : function ()
		{
			if (this._appFireTab.isOpen("TurnosAvellaneda"))
			{
				this._appFireTab.setFocusForm("TurnosAvellaneda");
			}
			else
			{
//				var form = new qx.ui.form.ow.FormTab("Turnos", "Turnos");
//				form.add(new caraffa.widgets.Turnos());
//				var form = new caraffa.widgets.TurnosAvellaneda();
				var form = new caraffa.widgets.Turnos(null, null, 2);
				this._appFireTab.openForm(form);
			}
			
		},
		BuscarTurnoPaciente : function ()
		{
			if (this._appFireTab.isOpen("id_buscar_turno"))
			{
				this._appFireTab.setFocusForm("id_buscar_turno");
			}
			else
			{
				var form = new caraffa.forms.BuscarTurnoPaciente();
				this._appFireTab.openForm(form);
			}
		},
		CompletarTurnos : function ()
		{
			if (this._appFireTab.isOpen("completar_turnos"))
			{
				this._appFireTab.setFocusForm("completar_turnos");
			}
			else
			{
				var form = new caraffa.forms.CompletarTurnos();
				this._appFireTab.openForm(form);
			}
		},
		ABMPacientes : function ()
		{
			if (this._appFireTab.isOpen("ABMPacientes"))
			{
				this._appFireTab.setFocusForm("ABMPacientes");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("ABMPacientes", "ABM Pacientes");
				var ABMPacientes = caraffa.widgets.ABMMaestros.getABMPacientes();
//				ABMPacientes.addListener("insert", function (e) {
//					
//					var rpc = new qx.io.remote.Rpc();
//					rpc.setTimeout(10000);
//					rpc.setUrl(caraffa.Funciones.rpcRemoto);
//					rpc.setCrossDomain(true);
//					rpc.setServiceName("ABMPacientes");
//					
//					var app = this;
//			        rpc.callAsync(function (result, ex, id) {
//			        	if (ex == null) {
//			        		return true;
//			        	} else {
//			        		alert(ex);
//			        	}
//			        },"opAlta", e.getData());
//				}, this);
				
				form.add(ABMPacientes);
				this._appFireTab.openForm(form);
			}
		},		
		Desktop : function ()
		{
			if (this._appFireTab.isOpen("Destkop"))
			{
				this._appFireTab.setFocusForm("Destkop");
			}
			else
			{
				var form = new caraffa.forms.Desktop();
				this._appFireTab.openForm(form);
			}
		},
		Anotador : function ()
		{
			if (this._appFireTab.isOpen("Anotador"))
			{
				this._appFireTab.setFocusForm("Anotador");
			}
			else
			{
				var form = new caraffa.forms.Anotador();
				this._appFireTab.openForm(form);
			}
		},		
// Medico		
		ABMAgenda : function ()
		{
			if (this._appFireTab.isOpen("ABMAgenda"))
			{
				this._appFireTab.setFocusForm("ABMAgenda");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("ABMAgenda", "ABMAgenda");
				switch (this._perfilUsuario.cod_tipo_usuario)
				{
					case '3':
						form.add(new caraffa.widgets.ABMAgenda());
					break;
					default:
						form.add(new caraffa.widgets.ABMAgenda(true));
					break;
				}
				this._appFireTab.openForm(form);
			}
		},
		AgendaMedico : function ()
		{
			if (this._appFireTab.isOpen("AgendaMedico"))
			{
				this._appFireTab.setFocusForm("AgendaMedico");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("AgendaMedico", "Turnos Semana");
				form.add(new caraffa.widgets.AgendaMedico());
				this._appFireTab.openForm(form);
			}
		},		
		DuracionTurno : function ()
		{
			if (this._appFireTab.isOpen("ABMDuracionTurno"))
			{
				this._appFireTab.setFocusForm("ABMDuracionTurno");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("ABMDuracionTurno", "ABMDuracionTurno");
				switch (this._perfilUsuario.cod_tipo_usuario)
				{
					case '3':
						form.add(new caraffa.widgets.DuracionTurno());
					break;
					default:
						form.add(new caraffa.widgets.DuracionTurno(true));
					break;
				}
				this._appFireTab.openForm(form);
			}
		},				
		HistoriasClinicas : function ()
		{
			if (this._appFireTab.isOpen("HistoriasClinicas"))
			{
				this._appFireTab.setFocusForm("HistoriasClinicas");
			}
			else
			{
				var fecha = new qx.util.format.DateFormat("dd/MM/yyyy");
				var fecha = fecha.format(new Date());
				var form = new caraffa.forms.HistoriasClinicas(fecha);
				this._appFireTab.openForm(form);
			}
		},				
		Cirugias : function ()
		{
			if (this._appFireTab.isOpen("Cirugias"))
			{
				this._appFireTab.setFocusForm("Cirugias");
			}
			else
			{
				var fecha = new qx.util.format.DateFormat("dd/MM/yyyy");
				var fecha = fecha.format(new Date());
				var form = new caraffa.forms.Cirugias(fecha,this._perfilUsuario.cod_tipo_usuario);
				this._appFireTab.openForm(form);
			}
		},	
// Administracion
		ABMUsuarios : function ()
		{
			if (this._appFireTab.isOpen("ABMUsuarios"))
			{
				this._appFireTab.setFocusForm("ABMUsuarios");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("ABMUsuarios", "ABM Usuarios");
				form.add(caraffa.widgets.ABMMaestros.getABMUsuarios());
				this._appFireTab.openForm(form);
			}
		},
		ABMGrupos : function ()
		{
			if (this._appFireTab.isOpen("ABMGrupos"))
			{
				this._appFireTab.setFocusForm("ABMGrupos");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("ABMGrupos", "ABM Grupos");
				form.add(caraffa.widgets.ABMMaestros.getABMTiposUsuarios());
				this._appFireTab.openForm(form);
			}
		},		
// Caja		
		CajaActualCaraffa : function ()
		{
			if (this._appFireTab.isOpen("CajaActualZipoli"))
			{
				this._appFireTab.setFocusForm("CajaActualZipoli");
			}
			else
			{
				var form = new caraffa.forms.Caja('C', '1');
				this._appFireTab.openForm(form);
			}
		},
		CajaActualAvellaneda : function ()
		{
			if (this._appFireTab.isOpen("CajaActualAvellaneda"))
			{
				this._appFireTab.setFocusForm("CajaActualAvellaneda");
			}
			else
			{
				var form = new caraffa.forms.Caja('C', '2');
				this._appFireTab.openForm(form);
			}
		},		
		CajaControl : function ()
		{
			if (this._appFireTab.isOpen("CajaControl"))
			{
				this._appFireTab.setFocusForm("CajaControl");
			}
			else
			{
				var form = new caraffa.forms.CajaControl();
				this._appFireTab.openForm(form);
			}
		},
		ABMCajaRubros : function ()
		{
			if (this._appFireTab.isOpen("ABMCajaRubros"))
			{
				this._appFireTab.setFocusForm("ABMCajaRubros");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("ABMCajaRubros", "ABM Caja Rubros");
				form.add(caraffa.widgets.ABMMaestros.getABMCajaRubros());
				this._appFireTab.openForm(form);
			}
		},		
//Caja		
//		CajaIngresoDiario : function ()
//		{
//			if (this._appFireTab.isOpen("CajaIngresoDiario"))
//			{
//				this._appFireTab.setFocusForm("CajaIngresoDiario");
//			}
//			else
//			{
//				var form = new qx.ui.form.ow.FormTab("CajaIngresoDiario", "Caja Ingreso Diario");
//				form.add(new caraffa.widgets.CajaIngresoDiario(this._perfilUsuario.cod_tipo_usuario));
//				this._appFireTab.openForm(form);
//			}
//		},
		CajaIngresoCustomZipoli : function ()
		{
			if (this._appFireTab.isOpen("CajaIngresosCustom"))
			{
				this._appFireTab.setFocusForm("CajaIngresosZipoli");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("CajaIngresosZipoli", "Caja - Ingresos Zipoli");
				form.add(new caraffa.widgets.CajaIngresoCustom(this._perfilUsuario.cod_tipo_usuario, 1));
				this._appFireTab.openForm(form);
			}
		},
		CajaIngresoCustomAvellaneda : function ()
		{
			if (this._appFireTab.isOpen("CajaIngresosAvellaneda"))
			{
				this._appFireTab.setFocusForm("CajaIngresosAvellaneda");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("CajaIngresosAvellaneda", "Caja - Ingresos Avellaneda");
				form.add(new caraffa.widgets.CajaIngresoCustom(this._perfilUsuario.cod_tipo_usuario, 2));
				this._appFireTab.openForm(form);
			}
		},
		Pagares : function ()
		{
			if (this._appFireTab.isOpen("Pagares"))
			{
				this._appFireTab.setFocusForm("Pagares");
			}
			else
			{
				var form = new caraffa.forms.Pagares();
				this._appFireTab.openForm(form);
			}
		},			
// STOCK		
		StockManejo : function ()
		{
			if (this._appFireTab.isOpen("StockManejo"))
			{
				this._appFireTab.setFocusForm("StockManejo");
			}
			else
			{
				var form = new caraffa.forms.StockManejo();
				this._appFireTab.openForm(form);
			}
		},
		StockMensual : function ()
		{
			if (this._appFireTab.isOpen("StockMes"))
			{
				this._appFireTab.setFocusForm("StockMes");
			}
			else
			{
				var fecha = new qx.util.format.DateFormat("MM/yy");
				var mesMostrar = fecha.format(new Date());
				var form = new caraffa.forms.StockMensual(mesMostrar);
				this._appFireTab.openForm(form);
			}
		},		
		ABMMarcas : function ()
		{
			if (this._appFireTab.isOpen("ABMMarcas"))
			{
				this._appFireTab.setFocusForm("ABMMarcas");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("ABMMarcas", "ABM Marcas");
				form.add(caraffa.widgets.ABMMaestros.getABMMarcas());
				this._appFireTab.openForm(form);
			}
		},
		ABMRubros : function ()
		{
			if (this._appFireTab.isOpen("ABMRubros"))
			{
				this._appFireTab.setFocusForm("ABMRubros");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("ABMRubros", "ABM Rubros");
				form.add(caraffa.widgets.ABMMaestros.getABMRubros());
				this._appFireTab.openForm(form);
			}
		},
		ABMArticulos : function ()
		{
			if (this._appFireTab.isOpen("ABMArticulos"))
			{
				this._appFireTab.setFocusForm("ABMArticulos");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("ABMArticulos", "ABM Articulos");
				form.add(caraffa.widgets.ABMMaestros.getABMArticulos());
				this._appFireTab.openForm(form);
			}
		},
		ABMProveedores : function ()
		{
			if (this._appFireTab.isOpen("ABMProveedores"))
			{
				this._appFireTab.setFocusForm("ABMProveedores");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("ABMProveedores", "ABM Proveedores");
				form.add(caraffa.widgets.ABMMaestros.getABMProveedores());
				this._appFireTab.openForm(form);
			}
		},
		ABMPartidas : function ()
		{
			if (this._appFireTab.isOpen("ABMPartidas"))
			{
				this._appFireTab.setFocusForm("ABMPartidas");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("ABMPartidas", "ABM Partidas");
				form.add(caraffa.widgets.ABMMaestros.getABMPartidas());
				this._appFireTab.openForm(form);
			}
		},
// Obras Sociales
		GeneraPlanillas : function ()
		{
			if (this._appFireTab.isOpen("GeneraPlanillas"))
			{
				this._appFireTab.setFocusForm("GeneraPlanillas");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("GeneraPlanillas", "Generación de Planillas");
				form.add(new caraffa.widgets.GeneraPlanillas());
				this._appFireTab.openForm(form);
			}
		},		
		ListaPlanillasOS : function ()
		{
			if (this._appFireTab.isOpen("ListaPlanillasOS"))
			{
				this._appFireTab.setFocusForm("ListaPlanillasOS");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("ListaPlanillasOS", "Listar Planillas");
				form.add(new caraffa.widgets.ListaPlanillasOS());
				this._appFireTab.openForm(form);
			}
		},				
		CheckPlanilla : function ()
		{
			if (this._appFireTab.isOpen("CheckPlanilla"))
			{
				this._appFireTab.setFocusForm("CheckPlanilla");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("CheckPlanilla", "Retorno de Planillas");
				form.add(new caraffa.widgets.CheckPlanilla());
				this._appFireTab.openForm(form);
			}
		},
		BalancesCarga : function ()
		{
			if (this._appFireTab.isOpen("id_balances_cargas"))
			{
				this._appFireTab.setFocusForm("id_balances_cargas");
			}
			else
			{
				var form = new caraffa.forms.BalancesCarga();
				this._appFireTab.openForm(form);
			}
		},
		BalancesListar : function ()
		{
			if (this._appFireTab.isOpen("id_balances_listar"))
			{
				this._appFireTab.setFocusForm("id_balances_listar");
			}
			else
			{
				var form = new caraffa.forms.BalancesListar();
				this._appFireTab.openForm(form);
			}
		},
		Derivaciones : function () {
			if (this._appFireTab.isOpen("Derivaciones"))
			{
				this._appFireTab.setFocusForm("Derivaciones");
			}
			else
			{
				var form = new caraffa.forms.Derivaciones();
				this._appFireTab.openForm(form);
			}
		},
		ABMPrestaciones : function ()
		{
			if (this._appFireTab.isOpen("ABMPrestaciones"))
			{
				this._appFireTab.setFocusForm("ABMPrestaciones");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("ABMPrestaciones", "ABM Prestaciones");
				form.add(caraffa.widgets.ABMMaestros.getABMPrestaciones());
				this._appFireTab.openForm(form);
			}
		},
		ABMPrestacionesRubros : function ()
		{
			if (this._appFireTab.isOpen("ABMPrestacionesRubros"))
			{
				this._appFireTab.setFocusForm("ABMPrestacionesRubros");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("ABMPrestacionesRubros", "ABM Prestaciones Rubros");
				form.add(caraffa.widgets.ABMMaestros.getABMPrestacionesRubros());
				this._appFireTab.openForm(form);
			}
		},		
		ABMPlanes : function ()
		{
			if (this._appFireTab.isOpen("ABMPlanes"))
			{
				this._appFireTab.setFocusForm("ABMPlanes");
			}
			else
			{
				var form = new qx.ui.form.ow.FormTab("ABMPlanes", "ABM Planes");
				form.add(new caraffa.widgets.ABMMaestros.getABMPlanes());
				this._appFireTab.openForm(form);
			}
		},
		CargaTurnos : function ()
		{
			if (this._appFireTab.isOpen("carga_turnos")) {
				this._appFireTab.setFocusForm("carga_turnos");
			} else {
				var form = new caraffa.forms.CargaTurnos();
				this._appFireTab.openForm(form);
			}
		},
		ABMNomenclador : function ()
		{
			if (this._appFireTab.isOpen("ABMNomenclador"))
			{
				this._appFireTab.setFocusForm("ABMNomenclador");
			}
			else
			{
				var form = new caraffa.forms.Nomenclador(this._perfilUsuario.cod_tipo_usuario);
				this._appFireTab.openForm(form);
			}
		},		
// Estadisticas
		ChartPacientesMedicoMes : function ()
		{
			if (this._appFireTab.isOpen("ChartPacientesMedicoMes"))
			{
				this._appFireTab.setFocusForm("ChartPacientesMedicoMes");
			}
			else
			{
				var form = new caraffa.forms.ChartPacientesMedicoMes();
				this._appFireTab.openForm(form);
			}
		},
		ChartOSCobradoPagado : function ()
		{
			if (this._appFireTab.isOpen("ChartOSCobradoPagado"))
			{
				this._appFireTab.setFocusForm("ChartOSCobradoPagado");
			}
			else
			{
				var form = new caraffa.forms.ChartOSCobradoPagado();
				this._appFireTab.openForm(form);
			}
		},
		ChartPacientesOSAnio : function ()
		{
			if (this._appFireTab.isOpen("ChartPacientesOSAnio"))
			{
				this._appFireTab.setFocusForm("ChartPacientesOSAnio");
			}
			else
			{
				var form = new caraffa.forms.ChartPacientesOSAnio();
				this._appFireTab.openForm(form);
			}
		},
		ChartNumerosGrales : function ()
		{
			if (this._appFireTab.isOpen("ChartNumerosGrales"))
			{
				this._appFireTab.setFocusForm("ChartNumerosGrales");
			}
			else
			{
				var form = new caraffa.forms.ChartNumerosGrales();
				this._appFireTab.openForm(form);
			}
		},
		ChartCPC : function ()
		{
			if (this._appFireTab.isOpen("ChartCPC"))
			{
				this._appFireTab.setFocusForm("ChartCPC");
			}
			else
			{
				var form = new caraffa.forms.ChartCPC();
				this._appFireTab.openForm(form);
			}
		},
		_CambiarPassword : function ()
		{
			var win = new qx.ui.window.Window("Cambio de Password");
			win.addListener("resize", win.center, win);
			win.set({width:350, height:140, showMaximize:false, allowMaximize:false, showMinimize:false, showClose:true, modal:true, movable:false, resizable:false, showStatusbar:false});
			win.setLayout(new qx.ui.layout.VBox(5));
			
			var txpPasswordActual = new qx.ui.form.ow.PassField("Password Actual:");
			var txpNewPassword1 = new qx.ui.form.ow.PassField("Password Nueva:");
			var txpNewPassword2 = new qx.ui.form.ow.PassField("Reescriba la Password:");
			var btnCambiar = new qx.ui.form.Button("Cambiar Password");
			
			txpPasswordActual.getText().addListener("keydown", function (e)
			{
				if (e.getKeyIdentifier() === 'Enter')
					txpNewPassword1.getText().tabFocus();
			}, this);
			
			txpNewPassword1.getText().addListener("keydown", function (e)
			{
				if (e.getKeyIdentifier() === 'Enter')
					txpNewPassword2.getText().tabFocus();
			}, this);
			
			txpNewPassword2.getText().addListener("keydown", function (e)
			{
				if (e.getKeyIdentifier() === 'Enter')
					btnCambiar.execute();
			}, this);
			
			btnCambiar.addListener("execute", function ()
			{
				if (txpNewPassword1.getValue() == txpNewPassword2.getValue())
				{
					var rpc = new qx.io.remote.Rpc();
					rpc.setTimeout(10000);
					rpc.setUrl("services/");
					rpc.setServiceName("login");
					var params = new Object();
					params.actual = txpPasswordActual.getValue();
					params.password = txpNewPassword1.getValue();
					try
					{
						var result = rpc.callSync("set_password", params);
						if (result)
						{
							alert("Se cambio correctamente la password.");
							win.close();
						}
						else
						{
							alert("No se cambio la password ya que ingreso mal la password actual.");
							txpPasswordActual.focus();
						}
					}
					catch (ex)
					{
						alert(ex);
					}
				}
				else
				{
					alert("No ingreso correctamente la password nueva.");
					txpNewPassword1.focus();
				}
			}, this);
			
			win.add(txpPasswordActual);
			win.add(txpNewPassword1);
			win.add(txpNewPassword2);
			win.add(btnCambiar);
			win.open();
			
			txpPasswordActual.focus();
		},
		_Bloquear : function ()
		{
			this._offTimer();
			var rpc = new qx.io.remote.Rpc();
			rpc.setTimeout(10000);
			rpc.setUrl("services/");
			rpc.setServiceName("login");
			try
			{
				var result = rpc.callSync("Logout");
				caraffa.Funciones.Login("Sistema Bloqueo. Indentifiquese para continuar.", this._perfilUsuario.usuario, this._onTimer, this);
			}
			catch (ex)
			{
				alert(ex);
			}
		},
		Logout : function ()
		{
			var rpc = new qx.io.remote.Rpc();
			rpc.setTimeout(10000);
			rpc.setUrl("services/");
			rpc.setServiceName("login");
			try
			{
				var result = rpc.callSync("Logout");
				location.reload(true);
			}
			catch (ex)
			{
				alert(ex);
			}
		}
	}
});
